package com.smart.oil.controller;

import com.smart.oil.aop.annotation.MyLog;
import com.smart.oil.entity.SmTech;
import com.smart.oil.service.TechService;
import com.smart.oil.utils.DataResult;
import com.smart.oil.vo.req.TechAddReqVO;
import com.smart.oil.vo.req.TechPageReqVO;
import com.smart.oil.vo.req.TechUpdateReqVO;
import com.smart.oil.vo.resp.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
@RestController
@RequestMapping("/api")
@Api(tags = "技术管理-最新技术成果",description = "技术管理相关接口")
public class TechController {
    /**
     *
     */
    @Autowired
    private TechService techService;

    @PostMapping("/techs")
    @ApiOperation(value = "分页获取技术信息数据接口")
    @MyLog(title = "技术管理-最新技术成果",action = "分页获取技术信息数据接口")
    @RequiresPermissions("sys:tech:list")
    public DataResult<PageVO<SmTech>> pageInfo(@RequestBody TechPageReqVO vo){
        DataResult result =DataResult.success();
        result.setData(techService.pageInfo(vo));
        return result;
    }
    @GetMapping("/tech/{id}")
    @ApiOperation(value = "获取技术信息数据详情接口")
    @MyLog(title = "技术管理-最新技术成果",action = "获取技术信息数据接口")
    @RequiresPermissions("sys:tech:detail")
    public DataResult<SmTech> detailInfo(@PathVariable("id") String id){
        DataResult result=DataResult.success();
        result.setData(techService.detailInfo(id));
        return result;
    }
    @PostMapping("/tech")
    @ApiOperation(value = "新增技术接口")
    @MyLog(title = "技术管理-最新技术成果",action = "新增技术接口")
    @RequiresPermissions("sys:tech:add")
    public DataResult addTech(@RequestBody @Valid TechAddReqVO vo){
        DataResult result=DataResult.success();
        techService.addTech(vo);
        return result;
    }


    @PutMapping("/tech")
    @ApiOperation(value = "更新最新技术接口")
    @MyLog(title = "技术管理-最新技术成果",action = "更新最新技术接口")
    @RequiresPermissions("sys:tech:update")
    public DataResult updateTech(@RequestBody @Valid TechUpdateReqVO vo){
        DataResult result=DataResult.success();
        techService.updateTech(vo);
        return result;
    }
    @DeleteMapping("/tech/{id}")
    @ApiOperation(value = "删除技术信息接口")
    @MyLog(title = "技术管理-最新技术成果",action = "删除技术信息接口")
    @RequiresPermissions("sys:tech:delete")
    public DataResult deletedTech(@PathVariable("id") String id){
        techService.deletedTech(id);
        DataResult result=DataResult.success();
        return result;
    }

}
